package  service
{
	import cn.inswf.framework.mvcs.Actor;
	import data.Chapter;
	import data.Lesson;
	import data.LMS;
	import event.PlayerEvent;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	/**
	 * ...
	 * @author lee
	 */
	public class DataLoader extends Actor 
	{
		private var _loader:URLLoader;
		public function DataLoader() 
		{
			
		}
		override public function onRegister():void 
		{
			super.onRegister();
			_loader = new URLLoader();
			_loader.addEventListener(Event.COMPLETE, loader_complete);
			_loader.load(new URLRequest("xml/swf.xml"));
		}
		
		private function loader_complete(e:Event):void 
		{
			var xml:XML = new XML(_loader.data);
			var attrib:XMLList = xml.attributes();
			var len:int = attrib.length();
			for (var i:int = 0; i < len; i++) {
				var attrXml:XML = attrib[i];
				var name:String = attrXml.localName();
				var value:String = attrXml.toString();
				Config.setParam(name, value);
			}
			var childs:XMLList = xml.children();
			len = childs.length();
			for (i = 0; i < len; i++) {
				new Chapter(childs[i]);
			}
			Chapter.lessonCount = Lesson.index-1;
			var rectstr:String = Config.getParam("movieRect");
			if (rectstr != null) {
				var p:Array = rectstr.split(",");
				if (p.length == 4) {
					Config.rect = new Rectangle(p[0], p[1], p[2], p[3]);
				}
			}
			if (Config.rect == null) {
				Config.rect = new Rectangle(0, 0, Config.width, Config.height);
			}
			LMS.id=Config.getParam("id");
			dispatchEvent(new PlayerEvent(PlayerEvent.CHAPTER_LOADED));
		}
		
	}

}